<?php
	require_once '../libs/app.config.php';
	require_once INCLUDE_PATH.'template.config.php';
	$charset?null:$charset='cn';

	$charset = $tpm->escape($charset);
	$script_url=basename($_SERVER['PHP_SELF']);
	$as=explode('.',$script_url);
	$bs=explode('_',$as[0]);
	$script_url=$bs[0];
	switch($script_url){
		case 'index':
			$nav=0;
			break;
		case 'about':
			$nav=1;
			break;
		case 'cargo':
			$nav=2;
			break;
		case 'express':
		case 'tracking':
			$nav=3;
			break;
		case 'latest':
			$nav=4;
			break;
		case 'contact':
			$nav=5;
			break;
		default:
			$nav=0;
			break;
	}
	$sql="select * from index_images where is_show=1";
	$query=$tpm->query($sql);
	while($row=$tpm->fetch_array($query)){
		$row['images_url']="../public/images_hot/ori/".$row['images_url'];
		$hot_list[] = $row;
	}
	$sql = sprintf('select a.* from articles a, article_cat ac  ' .
			'where ac.id=a.cat_id and ac.cat_name="CONTACT" ' .
			'and a.type="%s"',$charset);
	$query = $tpm->query($sql);
	while($row = $tpm->fetch_array($query)){
		$row = array('title'=>$row['title'],'content'=>$row['content']);
		$contact[] = $row;
	}

	/** adv **/
	//将模块名读出，并入$position_list
	$sql = sprintf('select acs.* from article_cat acs,article_cat acp where acp.id=acs.partent_id and (acp.cat_name="%s" or acp.cat_name="%s")',"CARGO SERVICES","EXPRESS SERVICES");
	$query = $tpm->query($sql);
	$rows=array();
	while($row=$tpm->fetch_array($query)){
		array_push($rows,$row['cat_name']);
	}
	$position_list= array('home_left_up','home_right_up','home_left_down','home_right_down','ABOUTUS','CONTACTUS');
	if(is_array($rows))$position_list = array_merge($position_list,$rows);
//	print_r($position_list);exit();
	foreach($position_list as $position_name){
		$sql = sprintf('select ac.* from adv_content ac,adv_position ap where ac.position_id=ap.id and ap.position_name="%s"',$position_name);
		$query = $tpm->query($sql);
		$row =$tpm->fetch_array($query);
		$row['content'] = '../public/images2/' .$row['content'];
		$$position_name = $row;
		$tpl->assign("$position_name",$$position_name);
	}

	/* */
	$sql = sprintf('select acs.* from article_cat acs, article_cat acp where acs.partent_id=acp.id and acp.cat_name="%s" order by sort_order asc',"CARGO SERVICES");
	$query = $tpm->query($sql);$m=1;
	while($row=$tpm->fetch_array($query)){
		if($m++==1){
			$cargo_str_cn.='<li><a href="cargo.php?charset=cn&cat_name='.$row['cat_name'].'">'.$row['cat_name_en'].'</a></li>';
			$cargo_str_en.='<li><a href="cargo.php?charset=en&cat_name='.$row['cat_name'].'">'.$row['cat_name'].'</a></li>';
		}else{
			$cargo_str_cn.='<li>|</li>'.'<li><a href="cargo.php?charset=cn&cat_name='.$row['cat_name'].'">'.$row['cat_name_en'].'</a></li>';
			$cargo_str_en.='<li>|</li>'.'<li><a href="cargo.php?charset=en&cat_name='.$row['cat_name'].'">'.$row['cat_name'].'</a></li>';
		}

		$cargo_list[] = $row;
	}
	/* */
	$sql = sprintf('select acs.* from article_cat acs, article_cat acp where acs.partent_id=acp.id and acp.cat_name="%s" order by sort_order asc',"EXPRESS SERVICES");
	$query = $tpm->query($sql);$i=1;$j=1;
	while($row=$tpm->fetch_array($query)){
		if($row['cat_name']=="Express Tracking"){
			if($i==1){
				$express_str_cn.='<li>|</li>'.'<li><a href="tracing.php?charset=cn&cat_name='.$row['cat_name'].'">'.$row['cat_name_en'].'</a></li>';
				$express_str_en.='<li>|</li>'.'<li><a href="tracing.php?charset=en&cat_name='.$row['cat_name'].'">'.$row['cat_name'].'</a></li>';
			}else{
				$express_str_cn.='<li>|</li>'.'<li><a href="tracing.php?charset=cn&cat_name='.$row['cat_name'].'">'.$row['cat_name_en'].'</a></li>';
				$express_str_en.='<li>|</li>'.'<li><a href="tracing.php?charset=en&cat_name='.$row['cat_name'].'">'.$row['cat_name'].'</a></li>';
			}
			$i++;
		}else{
			if($j==1){
				$express_str_cn.='<li><a href="express.php?charset=cn&cat_name='.$row['cat_name'].'">'.$row['cat_name_en'].'</a></li>';
				$express_str_en.='<li><a href="express.php?charset=en&cat_name='.$row['cat_name'].'">'.$row['cat_name'].'</a></li>';
			}else{
				$express_str_cn.='<li>|</li>'.'<li><a href="express.php?charset=cn&cat_name='.$row['cat_name'].'">'.$row['cat_name_en'].'</a></li>';
				$express_str_en.='<li>|</li>'.'<li><a href="express.php?charset=en&cat_name='.$row['cat_name'].'">'.$row['cat_name'].'</a></li>';
			}
			$j++;
		}

		$express_list[] = $row;
	}


	$tpl->assign("cargo_str_cn",$cargo_str_cn);
	$tpl->assign("cargo_str_en",$cargo_str_en);
	$tpl->assign("cargo_list",$cargo_list);

	$tpl->assign("express_str_cn",$express_str_cn);
	$tpl->assign("express_str_en",$express_str_en);
	$tpl->assign("express_list",$express_list);

//	print_r($contact[0]);
	$tpl->assign('contact',$contact[0]);
	$tpl->assign('hot_list',$hot_list);
	$tpl->assign('maxFrame',count($hot_list));
	$tpl->assign("top_nav",$nav);